#include <stdio.h>

#define SIZE 4

int dimension;
int maxvalue, rooknum;
char board[SIZE][SIZE+1];

int max(int a, int b){
	return a>b?a:b;
}

int isLegal(int row, int col){
	int i;
	for (i=col-1; i>=0&&board[row][i]=='.'; i--);
	if (i>=0&&board[row][i]=='r') return 0;
	for (i=row-1; i>=0&&board[i][col]=='.'; i--);
	if (i>=0&&board[i][col]=='r') return 0;
	return 1;
}

void backtrack(int depth){
	if (depth==dimension*dimension){
		maxvalue=max(rooknum,maxvalue);
		return;
	}
	int row = depth / dimension, col = depth % dimension;
	if (board[row][col]=='.'&&isLegal(row, col)) {
		board[row][col]='r';
		rooknum++;
		backtrack(depth+1);
		board[row][col]='.';
		rooknum--;
	}
	backtrack(depth+1);
}

int main (int argc, const char * argv[]) {
	int i;
	while (scanf("%d",&dimension),dimension) {
		for (i=0; i<dimension; i++) scanf("%s",board[i]);
		maxvalue=rooknum=0;
		backtrack(0);
		printf("%d\n",maxvalue);
	}
    return 0;
}
